package com.netistate.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.gson.Gson;
import com.netistate.base.BaseAction;
import com.netistate.pojo.ClientContact;
import com.netistate.pojo.Demo;
import com.netistate.pojo.Doc;
import com.netistate.pojo.Labor;
import com.netistate.pojo.Project;
import com.netistate.pojo.ProjectBlog;
import com.netistate.pojo.ProjectServiceDetail;
import com.netistate.pojo.ProjectServices;
import com.netistate.pojo.ProjectTypeDefine;
import com.netistate.pojo.Sale;
import com.netistate.pojo.TechNote;
import com.netistate.pojo.User;
import com.netistate.pojo.UserProject;
import com.netistate.service.LaborService;
import com.netistate.service.ProjectService;
import com.netistate.service.UserService;
import com.netistate.util.AddListUtil;
import com.netistate.util.GetNowTime;
import com.netistate.util.MailUtil;
import com.netistate.util.ServiceAndInfoTypeMapUtil;

public class ProjectAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	private ProjectService projectService;
	private UserService userService;
	private LaborService laborService;
	
	//对项目表
	private String projectName;
	private String projectManager;
	private String desc;
	private String projectProcess;
	private String process;
	private String clientName;
	private String clientAddress;
	private String manager;
	private String members;
	private String id;
	private String pid;
	
	private String starttime;
	private String endtime;
	
	//ServiceInfoType
	private String serviceNo;
	private String hours;
	private String otherPeople;
	private String serviceType;
	private String ourPeoples;
	
	private String i1;
	private String i2;
	private String i3;
	private String i4;
	private String i5;
	private String i6;
	private String i7;
	private String i8;
	private String i9;
	private String i10;
	private String i11;
	private String i12;
	private String i13;
	private String i14;
	private String i15;
	
	//对项目下的服务记录表的操作
	private String type;
	private String supportDate;
	private String workContent;
	private String goal;
	private String focusContent;
	private String nextStep;
	private String rivalMsg;
	private String idea;
	private String other;
	private String leftProblem;
	private String server;
	private String begintime;
	private String workNote;
	private String serNo;
	private String projectServiceType;
	private String infoType;
	private String psid;
	
	private String insertClientContact;
	private String insertLabor;
	
	//对技术备忘录
	private String reporter;
	private String briefDesc;
	private String detailDesc;
	private String doer;
	private String state;
	private String techDemon;
	private String reportDate;
	private String closetime;
	private String level;
	private String qlevel;
	private String addtechNoteProjectId;
	private String editTechNoteStateid;
	private String editTechNoteState;
	private String projectTechNoteId;
	private String editTechNoteLevel;
	private String editTechDemon;
	private String editTechCloseDate;
	private String blurByProjectName;
	private String blurByClientName;
	
	
	//对项目接口人
	private String contactName;
	private String address;
	private String tel;
	private String company;
	private String email;
	private String projectClientId;
	
	//对文档上传
	private List<File> docList;
	private List<String> docListFileName;
	private List<String> docListContentType;
	private List<String> fileNameByHand;
	private String selectProjectId;
	private String projectServicesId;
	
	
	//对文档的下载
	private String mime;
	private String fileName;
	private long fileLength;
	private String docid;
	
	//读取properties文件获取file上传和下载路径,赋值给filePath
	private static String filePath = new String();
	static{
		Properties properties = new Properties();
		try {
			properties.load(ProjectAction.class.getClassLoader().getResourceAsStream("file.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		filePath = properties.getProperty("filePath");
	}
	
	private List<Project> projectList;
	private List<Sale> saleList;

	/**
	 * 添加项目
	 * @return
	 * @throws Exception
	 */
	@Action("add_project")
	public String add_project() throws Exception{
		
		String time = new GetNowTime().getNowTime(); 
		
		Project p = new Project();
		p.setProjectName(projectName);
		p.setAlias(projectName);
		p.setProjectManager(manager);
		p.setDescr(desc);
		p.setCreatetime(time);
		p.setProjectProcess(process);
		p.setClientName(clientName);
		p.setClientAddress(clientAddress);
		p.setProjectMember(members);
		User u = userService.findUserByUsername(manager);
		
		//把项目存到项目表中
		projectService.saveProject(p);
		
		
		//把项目和项目管理者存到关系表里
		UserProject up = new UserProject();
		up.setProject(p);
		up.setUser(u);
		
		projectService.saveUserAndProject(up);
		
		//把项目成员存到关系表中
		String[] mems = members.split(",");
		for(String mem : mems){
			//此时项目管理员和成员重复(重复不保存)
			if(mem.equals(manager)){
				//不做处理
			} else {
				User us = userService.findUserByUsername(mem);
				UserProject ups = new UserProject();
				ups.setProject(p);
				ups.setUser(us);
				
				projectService.saveUserAndProjectMember(ups);
			}
		}
		
		//发送邮件
		List<UserProject> upList = projectService.findUserProjectByPid(p.getId());
		
		User user = (User) getSession().get("session_user");
		
		String emailMsg = user.getRealName()+"新建了'"+p.getProjectName()+"'的项目！描述为：" + p.getDescr() + "'";
		String emailsubject = "新建'"+p.getProjectName()+"'项目！"; 
		
		for(UserProject ups : upList){
			String sendEmailAddress = ups.getUser().getEmail();
			MailUtil.sendMail(sendEmailAddress, emailsubject, emailMsg);
		}
		
		
		//把相关信息存到日志表里
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(p);
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(time);
		pb.setDescr(sessionUser.getRealName()+"创建了"+p.getProjectName()+"项目。");
		
		projectService.saveProjectBlog(pb);
		return null;
	}
	
	/**
	 * 根据服务类型查
	 * @return
	 * @throws Exception
	 */
	@Action(value="findProjectServiceTypeByServiceType",results={@Result(name="success",type="dispatcher",location="/jsp/project/showInfoByServiceType.jsp")})
	public String findProjectServiceTypeByServiceType() throws Exception{
		List<ProjectServiceDetail> psdList = projectService.findProjectServiceByServiceType(pid,projectServiceType);
		getRequest().setAttribute("infoByServiceType",psdList);
		return SUCCESS;
	}
	
	/**
	 * 根据信息类型查
	 * @return
	 * @throws Exception
	 */
	@Action(value="findInfoByinfoType",results={@Result(name="success",type="dispatcher",location="/jsp/project/showInfoByInfoType.jsp")})
	public String findInfoByinfoType() throws Exception{
		
		
		List<ProjectServiceDetail> psdList = projectService.findProjectServiceDetailByInfoType(pid,infoType);
		getRequest().setAttribute("infoByInfoType", psdList);
		return SUCCESS;
	}
	
	
	
	/**
	 * 查询所有工作记录
	 * @return
	 * @throws Exception
	 */
	@Action(value="find_all_workNote",results={@Result(name="success",type="dispatcher",location="/jsp/project/showProjectServices.jsp")})
	public String find_all_workNote() throws Exception{
		
		int projectId = Integer.parseInt(pid);
		List<ProjectServices> psList = projectService.findProjectServicesByProjectId(projectId);
		getRequest().setAttribute("projectServicesByPid", psList);
		return SUCCESS;
	}
	
	/**
	 * 查询项目下全部的ProjectServices
	 */
	@Action(value="findAllProjectServices",results={@Result(name="success",type="dispatcher",location="/jsp/project/project_id.jsp")})
	public String findAllProjectServices() throws Exception{
		List<ProjectServices> psList = projectService.findAllProjectServicesByPid(Integer.parseInt(pid));
		getRequest().setAttribute("PprojectServicesList", psList);
		return SUCCESS;
	}
	
	/**
	 * 查询所有技术备忘录
	 * @return
	 * @throws Exception
	 */
	@Action("findAllTechNote")
	public String findAllTechNote() throws Exception{
		List<TechNote> techNoteList = projectService.findAllTechNote();
		getSession().put("techNoteList", techNoteList);
		return null;
	}
	
	/**
	 * 技术备忘录里的按条件查询，，不在项目下
	 * @return
	 * @throws Exception
	 */
	@Action(value="query_techNote_by_Condition",results={@Result(name="success",location="/jsp/techNote/techNote.jsp")})
	public String query_techNote_by_Condition() throws Exception{
		
		String states = this.getState();  
		String[] arraycheck = states.split(", ");
		
		List<TechNote> tNList = new ArrayList<TechNote>();
		List<TechNote> techNoteList = new ArrayList<TechNote>();
		
		for(String s : arraycheck){
			tNList = projectService.findTechNoteByCondition(pid,s,level,reporter,doer,begintime,endtime);
			techNoteList.addAll(tNList);
		}
		
		System.out.println("techNoteList:>:>:>:>:"+techNoteList.size());
		//把查询的值用request带过去
		getRequest().setAttribute("tnList", techNoteList);
		
		//查询的信息要遗留在输入框或者选择框中
		getRequest().setAttribute("queryPid", pid);
		if(!(pid == null || "所有".equals(pid))){
			Project p = projectService.findProjectById(Integer.parseInt(pid));
			getRequest().setAttribute("queryPidProject", p);
		}
		
		getRequest().setAttribute("queryState", state);
		getRequest().setAttribute("queryLevel", level);
		
		getRequest().setAttribute("queryReporter", reporter);
		System.out.println("reporter:"+reporter);
		if(!(reporter == null || "所有".equals(reporter))){
			//根据username去找user
			User user = projectService.findUserByUsername(reporter);
			getRequest().setAttribute("queryReporterUser", user);
		}
		
		getRequest().setAttribute("queryDoer", doer);
		if(!(doer == null || "所有".equals(doer))){
			//根据username去找user
			User user = projectService.findUserByUsername(doer);
			getRequest().setAttribute("queryDoerUser", user);
		}
		
		getRequest().setAttribute("queryTechNoteBegintime", begintime);
		getRequest().setAttribute("queryTechNoteEndtime", endtime);
		return SUCCESS;
	}
	
	/**
	 * 根据项目条件去查询匹配的项目,带着值返回到project.jsp
	 * @return
	 * @throws Exception
	 */
	@Action(value="queryProjectByCondition",results={@Result(name="success",location="/jsp/project/project.jsp")})
	public String queryProjectByCondition() throws Exception{
		
		projectList = projectService.queryProjectByCondition(projectManager,starttime,endtime,projectProcess);
		getRequest().setAttribute("pl", projectList);
		
		getRequest().setAttribute("queryProjectManager", projectManager);
		if(!(projectManager == null || "所有".equals(projectManager))){
			//根据username去找user
			User user = projectService.findUserByUsername(projectManager);
			getRequest().setAttribute("queryProjectManagerUser", user);
		}
		getRequest().setAttribute("queryProjectStarttime", starttime);
		getRequest().setAttribute("queryProjectEndtime", endtime);
		getRequest().setAttribute("queryProjectProcess", projectProcess);
		
		return SUCCESS;
	}
	/**
	 * 查找所有项目
	 * @return
	 * @throws Exception
	 */
	@Action("findAllProject")
	public String findAllProject() throws Exception{
		//projectList = projectService.findAll();
		//getSession().put("projectList", projectList);
		projectList = projectService.findProjectListInOneMonth();
		getSession().put("projectListInOneMonth", projectList);
		return null;
	}
	
	/**
	 * 查询并显示日志
	 * @return
	 * @throws Exception
	 */
	@Action(value="showLog",results={@Result(name="success",type="dispatcher",location="/jsp/project/showLog.jsp")})
	public String showLog() throws Exception{
		
		List<ProjectBlog> projectBlogList = projectService.findAllProjectBlogByPid(Integer.parseInt(id));
		getSession().put("projectBlogList",projectBlogList);
		return SUCCESS;
	}
	
	/**
	 * 查看相关的产品和Demo信息，就是找到这个project，然后去找出productList,demoSet
	 * @return
	 * @throws Exception
	 */
	@Action(value="lookProductDemoMsg",results={@Result(name="success",type="dispatcher",location="/jsp/demo/showProductDemoMsg.jsp")})
	public String lookProductDemoMsg() throws Exception {
		
		System.out.println("pid:"+pid);
		
		Project p = projectService.findProjectById(Integer.parseInt(pid));
		getSession().put("showPDproject", p);
		
		return SUCCESS;
	}
	
	/**
	 * 点击具体某个项目后，进入下个页面，把id传过去，并默认查找所有项目下的服务记录表
	 */
	@Override
	@Action(value="selectProject",results={@Result(name="success",type="dispatcher",location="/jsp/project/project_id.jsp")})
	public String execute() throws Exception {
		getSession().put("projectid", id);
		
		int pid = Integer.parseInt(id);
		Project p = projectService.findProjectById(pid);
		
		getSession().put("selectProject", p);
		
		System.out.println("查找ps");
		//查找ProjectServices,返回list
		List<ProjectServices> projectServicesList = projectService.findAllProjectServicesByPid(pid);
		System.out.println("找完，然后list.size=："+projectServicesList.size());
		getSession().put("projectServicesList", projectServicesList);
		
		return SUCCESS;
	}
	
	
	
	/**
	 * 点击添加项目服务表时，去找project,用以在下面展现productList，返回到addSale.jsp页面,否则会报懒加载问题
	 * @return
	 * @throws Exception
	 */
	@Action(value="show_sale",results={@Result(name="success",type="dispatcher",location="/jsp/project/addSale.jsp")})
	public String show_sale() throws Exception{
		
		int pid = Integer.parseInt(id);
		Project p = projectService.findProjectById(pid);
		
		getSession().put("selectProjectInSale", p);
		
		return SUCCESS;
	}
	
	/**
	 * 双击项目描述，弹框，显示项目信息和项目接口人信息
	 * @return
	 * @throws Exception
	 */
	@Action(value="show_project_detail",results={@Result(name="success",type="dispatcher",location="/jsp/project/showProjectDetail.jsp")})
	public String show_project_detail() throws Exception{
		int ppid = Integer.parseInt(id);
		Project p = projectService.findProjectById(ppid);
		getSession().put("projectDetailById", p);
		
		return SUCCESS;
	}

	/**
	 * 选中一个ProjectServices
	 * @return
	 * @throws Exception
	 */
	@Action("select_editProjectServices")
	public String select_editProjectServices() throws Exception{
		
		ProjectServices ps = projectService.findProjectServicesByPSId(Integer.parseInt(psid));
		List<ProjectServiceDetail> psdList = projectService.findProjectServiceDetailByPSId(Integer.parseInt(psid));
		
		getSession().put("selectProjectServices", ps);
		getSession().put("selectPSDetailList", psdList);
		return null;
	}
	
	/**
	 * 更新ProjectServices
	 * @return
	 * @throws Exception
	 */
	@Action("update_projectServices")
	public String update_projectServices() throws Exception{
		
		
		//把infoNo和infoContent全放在list里，然后在后面以":"进行截取
		List<String> infoList = AddListUtil.getListUtil(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15);
		
		//找到projectServices
		ProjectServices ps = projectService.findProjectServicesByPSId(Integer.parseInt(psid));
		
		//一个个在projectServiceDetail里更新值,
		for(String s : infoList){
			List<ProjectServiceDetail> psdList = projectService.findProjectServiceDetailByPSId(Integer.parseInt(psid));
			
			String iNo = s.substring(0,s.lastIndexOf("&"));
			String iContent = s.substring(s.lastIndexOf("&")+1,s.length());
			
			for(int i = 0; i < psdList.size(); i++){
				if(psdList.get(i).getInfoTypeNo().equals(iNo)){
					psdList.get(i).setWorkNote(iContent);
				}
			}
		}
		
		ps.setAddress(address);
		ps.setSupportDate(supportDate);
		ps.setHours(Float.parseFloat(hours));
		ps.setOtherPeople(otherPeople);
		ps.setOurPeople(ourPeoples);
		ps.setServiceType(serviceType);
		
		projectService.saveProjectServices(ps);
		
		//向项目日志里存数据
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(ps.getProject());
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"修改了"+ps.getProject().getProjectName()+"下的服务记录的基本信息！");
		
		projectService.saveProjectBlog(pb);
		
		return null;
	};
	
	/**
	 * 删除服务记录表，还会首先级联删除文档和服务记录详细表的内容
	 * @return
	 * @throws Exception
	 */
	@Action("delete_projectServices")
	public String  delete_projectServices() throws Exception{
		
		int pssid = Integer.parseInt(psid);
		
		//有文档的话先删除文档里的内容
		projectService.delProjectServicesDoc(pssid);
		
		//删除服务记录表定义里的内容
		projectService.delProjectServicesDetail(pssid);
		
		//最后删除服务记录表的内容
		projectService.delProjectServices(pssid);
		return null;
	}
	
	/**
	 * 点击项目后，选择项目下的销售表，然后查找，放session,展现(未完成)
	 * @return
	 * @throws Exception
	 */
	@Action(value="selectSale",results={@Result(name="success",location="/jsp/project/project_sale.jsp")})
	public String selectSale() throws Exception{
		/*int pid = Integer.parseInt(id);
		saleList = projectService.findAllSaleByPid(pid);
		getSession().put("saleList", saleList);*/
		return SUCCESS;
	}
	
	/**
	 * 对某项目下的服务记录表进行增加操作
	 */
	@Override
	@Action("add_project_sale")
	public String save() throws Exception {
		
		int pid = Integer.parseInt(id);
		Project p = projectService.findProjectById(pid);
		User user = (User)getSession().get("session_user");
		
		
		//先在ProjectService表插入值
		ProjectServices ps = new ProjectServices();
		ps.setServiceName(ServiceAndInfoTypeMapUtil.getServiceTypeName(serviceNo));
		ps.setServiceNo(serviceNo);
		ps.setServiceType(serviceType);
		ps.setSupportDate(supportDate);
		ps.setAddress(address);
		ps.setHours(Float.parseFloat(hours));
		ps.setOtherPeople(otherPeople);
		ps.setOurPeople(ourPeoples);
		ps.setCreatetime(new GetNowTime().getNowTime());
		ps.setProject(p);
		
		projectService.saveProjectServices(ps);
		
		System.out.println("serviceNo:>:>:>:>:>:>:"+serviceNo);
		
		//把projectServiceId放在session中，以便添加文档时使用
		getSession().put("projectServicesId", ps.getId());
		
		//把infoNo和infoContent全放在list里，然后在后面以"&"进行截取
		List<String> infoList = AddListUtil.getListUtil(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15);
		
		//一个个在projectServiceDetail里插入值,
		for(String s : infoList){
			
			String iNo = s.substring(0,s.lastIndexOf("&"));
			String iContent = s.substring(s.lastIndexOf("&")+1,s.length());
			
			ProjectServiceDetail psd = new ProjectServiceDetail();
			psd.setInfoTypeNo(iNo);
			psd.setInfoTypeName(ServiceAndInfoTypeMapUtil.getInfoTypeName(iNo));
			psd.setWorkNote(iContent);
			psd.setProjectServices(ps);
			
			projectService.saveProjectServiceDetail(psd);
		}
		
		//如果serviceNo为s1,s2,s3,s4的话，工时中的描述就为 工作内容 i2这个infoName,判断后再进行对工时的操作
		if("s1".equals(serviceNo) || "s2".equals(serviceNo) || "s3".equals(serviceNo) || "s4".equals(serviceNo)){
			
			//勾选checkbox后操作工时表
			if("1".equals(insertLabor)){
				Labor l = new Labor();
				if("客户现场".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i2);//这里为i2,即工作内容
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(1);
				}
				if("远程支持".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i2);//这里为i2,即工作内容
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("技术支持");
					l.setLocale(0);
				}
				if("电话会议".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i2);//这里为i2,即工作内容
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(0);
				}
				if("公司会议".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i2);//这里为i2,即工作内容
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(0);
				}
				if("其他".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i2);//这里为i2,即工作内容
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(0);
				}
				laborService.save(l);
			}
		}
		
		//如果serviceNo为s5,s6,s8的话，工时中的描述就为 交流信息纪要i5 这个infoName,判断后再进行对工时的操作
		if("s5".equals(serviceNo) || "s6".equals(serviceNo) || "s8".equals(serviceNo)){
			
			//勾选checkbox后操作工时表
			if("1".equals(insertLabor)){
				Labor l = new Labor();
				if("客户现场".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i5);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(1);
				}
				if("远程支持".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i5);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("技术支持");
					l.setLocale(0);
				}
				if("电话会议".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i5);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(0);
				}
				if("公司会议".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i5);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(0);
				}
				if("其他".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i5);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(0);
				}
				laborService.save(l);
			}
		}
		
		//如果serviceNo为s7的话，工时中的描述为 文档说明i10  这个infoName,判断后再进行对工时的操作
		if("s7".equals(serviceNo)){
			
			//勾选checkbox后操作工时表
			if("1".equals(insertLabor)){
				Labor l = new Labor();
				if("客户现场".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i10);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(1);
				}
				if("远程支持".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i10);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("技术支持");
					l.setLocale(0);
				}
				if("电话会议".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i10);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(0);
				}
				if("公司会议".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i10);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(0);
				}
				if("其他".equals(serviceType)){
					l.setCreatetime(new GetNowTime().getNowTime());
					l.setDatetime(supportDate);
					l.setDescr(i10);
					l.setHours(Float.parseFloat(hours));
					l.setProject(p);
					l.setProjectProcess(p.getProjectProcess());
					l.setUser(user);
					l.setSection("交流");
					l.setLocale(0);
				}
				laborService.save(l);
			}
		}
		
		
		//勾选checkbox后操作客户表
		if("1".equals(insertClientContact)){
			ClientContact cc = new ClientContact();
			cc.setContactName(otherPeople);
			cc.setProject(p);
			
			projectService.saveClientContact(cc);
		}
		
		//向项目日志里存数据
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(p);
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"在"+p.getProjectName()+"项目下新建了服务表！");
		
		projectService.saveProjectBlog(pb);
		
		return null;
	}

	/**
	 * 根据id去删除项目,要先级联删除日志和关系表中的记录,未在项目里日志里存信息
	 */
	@Override
	@Action("deleteProject")
	public String del() throws Exception {
		
		int pid = Integer.parseInt(id);
		//在service删除级联的部分
		List<UserProject> uplist = projectService.findUserProjectByPid(pid);
		//1.循环删除关系表
		for(UserProject up : uplist){
			projectService.deleteUserProject(up);
		}
		
		//2.删除产品
		projectService.delProductByProjectId(pid);
		
		//3.删除技术备忘录
		projectService.delTechNoteByProjectId(pid);
		
		//4.删除客户联系人
		projectService.delClientContactByProjectId(pid);
		
		//5.删除Demo
		projectService.delDemoByProjectId(pid);
		
		//6.删除projectService和projectServiceDetail和Doc
		projectService.delProjectServicesAndPSDByProjectId(pid);
		
		//7.删除projectBlog
		projectService.delprojectBlogByProjectId(pid);
		
		//8.删除工时
		projectService.delLaborByProjectId(pid);
		
		projectService.del(pid);
		
		return null;
	}
	//--------------------文档----------------------------------文档---------------------------文档-------------------------
	
	/**
	 * 切换项目下的文档记录
	 * @return
	 * @throws Exception
	 */
	@Action("look_project_doc")
	public String look_project_doc() throws Exception{
		
		List<Doc> docList = projectService.findAllDocByPid(Integer.parseInt(id));
		getSession().put("projectDocList", docList);
		return null;
	}
	
	/**
	 * 根据条件去查询工时，用request去把数据带回去
	 * @return
	 * @throws Exception
	 */
	@Action(value="query_doc_by_condition",results={@Result(name="success",location="/jsp/doc/doc.jsp")})
	public String query_doc_by_condition() throws Exception{

		List<Doc> dList = projectService.findDocByCondition(projectName,begintime,endtime);
		getRequest().setAttribute("dList", dList);
		
		//查询的信息要遗留在输入框或者选择框中
		getRequest().setAttribute("queryDocProjectName", projectName);
		if(!(projectName == null || "所有".equals(projectName))){
			Project p = projectService.findProjectById(Integer.parseInt(projectName));
			getRequest().setAttribute("queryDocProject", p);
		}
		
		getRequest().setAttribute("queryDocBegintime", begintime);
		getRequest().setAttribute("queryDocEndtime", endtime);
		
		return SUCCESS;
	}
	/**
	 * 查询所有文档
	 * @return
	 * @throws Exception
	 */
	@Action("findAllDoc")
	public String findAllDoc() throws Exception{
		List<Doc> docList = projectService.findAllDoc();
		getSession().put("docList", docList);
		return null;
	}
	/**
	 * 下载文档
	 * @return
	 * @throws Exception
	 */
	@Action(value="downDoc",results={@Result(name="success",type="stream",
										params={"contentType","${mime}",
												"contentLength","${fileLength}",
												"inputName","docStream",
												"contentDisposition","attachment;filename=${fileName}",
												"bufferSize","2048"})})
	public String downDoc() throws Exception{
		Doc doc = projectService.findDocById(Integer.parseInt(docid));
		String mimeType = doc.getType();
		long docFileLength = doc.getDocLength();
		String docFileName = doc.getDocName();
		
		//向项目日志里存数据
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(doc.getProject());
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"下载了名为："+doc.getDocName()+"的文档！");
		
		projectService.saveProjectBlog(pb);
		
		return SUCCESS;
	} 
	public InputStream getDocStream() throws Exception{
		
		Doc doc = projectService.findDocById(Integer.parseInt(docid));
		
		//String mimeType = doc.getType();
		//long docFileLength = doc.getDocLength();
		//String docFileName = doc.getDocName();
		
		
		//取得后缀
		//String extName = doc.getDocName().substring(doc.getDocName().lastIndexOf("."));
		
		
		setMime(doc.getType());
		setFileName(doc.getDocName());
		//存放文档的路径。。。。
		File file = new File(filePath + doc.getProject().getAlias() + "/" + doc.getDocNo() + "-" + doc.getDocName());
		setFileLength(doc.getDocLength());
		
		//getResponse().setHeader("Content-Disposition","attachment;fileName="+java.net.URLEncoder.encode(fileName, "UTF-8"));
		InputStream is = new FileInputStream(file);
		return is;
	}
	
	/**
	 * 文档的上传
	 * @return
	 * @throws Exception
	 */
	@Action(value="upload_doc"/*,results={@Result(name="success",location="/jsp/doc/onloadBack.jsp")}*/)
	public String upload_doc() throws Exception{
		
		//设置文件夹下存储的文件的名字，用时间来管理
		Date date = new Date();
		SimpleDateFormat sdfDocNo = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat createtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		//获取上传文件的所在的项目
		User u = (User) getSession().get("session_user");
		Project p = projectService.findProjectById(Integer.parseInt(selectProjectId));
		ProjectServices pss = projectService.findProjectServicesByPSId(Integer.parseInt(projectServicesId));
		
		for(int i = 0; i < docList.size(); i++){
			try {  
			
				//---读文件
				BufferedInputStream bis = new BufferedInputStream(new FileInputStream(docList.get(i)));
				
				String docFileName = docListFileName.get(i);
				//后缀
				String extName = docFileName.substring(docFileName.lastIndexOf("."));
				//文件名字
				String fileRealName = "";
				if("".equals(fileNameByHand.get(i)) || fileNameByHand.get(i) == null){
					//文件名字如没有写的话就是文件本身的名字
					fileRealName = docFileName;
				}else{
					//文件名称是如有手写的就是手写的
					fileRealName = fileNameByHand.get(i);
				}
				
				//对上传文件进行文件夹分类,只生成文件夹
				File uploadFile = new File(filePath + p.getAlias());
				
				//文件夹不存在就新建一个
				if(!uploadFile.exists()){
					uploadFile.mkdir();
				}
				
				//在新建或存在的文件夹下存放文件
				File outputFile = new File(uploadFile + "/" + sdfDocNo.format(date) + "-" + fileRealName );
				
				BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outputFile));
				byte[] buffer = new byte[1024];
				int len = -1;
				while((len = bis.read(buffer))!= -1) {
					bos.write(buffer, 0, len);
				}
				
				bos.flush();
				bos.close();
				bis.close();
				
				//------存数据库
				Doc d = new Doc();
				d.setDocNo(sdfDocNo.format(date));
				d.setDocName(fileRealName);
				d.setType(docListContentType.get(i));
				d.setCreater(u.getRealName());
				d.setCreatetime(createtime.format(date));
				d.setDocLength(docList.get(i).length());
				d.setProject(p);
				d.setProjectServices(pss);
				
				projectService.saveDoc(d);
		
				//向项目日志里存数据
				User sessionUser = (User) getSession().get("session_user");
				ProjectBlog pb = new ProjectBlog();
				pb.setProject(p);
				pb.setCreater(sessionUser.getUsername());
				pb.setCreatetime(new GetNowTime().getNowTime());
				pb.setDescr(sessionUser.getRealName()+"上传了名为："+fileRealName+"的文档！");
				
				projectService.saveProjectBlog(pb);
			} catch (IOException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
            }
			
			
		}
		//getResponse().setContentType("text/javascript;charset=UTF-8");
		getResponse().getWriter().print("<script type=\"text/javascript\">window.parent.uploadfileSuccess(1)</script>");
		return null;
	}
	
	//--------------------文档----------------------------------文档---------------------------文档-------------------------
	
	//---------------------技术备忘录----------------技术备忘录-------------------技术备忘录-----------------------
	
	
	/**
	 * 根据项目名称模糊查询技术备忘录
	 * @return
	 * @throws Exception
	 */
	@Action(value="blur_query_techNote_projectName",results={@Result(name="success",location="/jsp/techNote/techNote.jsp")})
	public String blur_query_techNote_projectName() throws Exception{
		
		System.out.println("blurByProjectName:"+blurByProjectName);
		
		List<TechNote> tnList = projectService.findTechNoteByProjectName(blurByProjectName);
		getRequest().setAttribute("tnList", tnList);
		
		return SUCCESS;
	}
	
	
	/**
	 * 根据客户名称模糊查询技术备忘录
	 * @return
	 * @throws Exception
	 */
	@Action(value="blur_query_techNote_clientName",results={@Result(name="success",location="/jsp/techNote/techNote.jsp")})
	public String blur_query_techNote_clientName() throws Exception {
		
		List<TechNote> tnList = projectService.findTechNoteByClientName(blurByClientName);
		getRequest().setAttribute("tnList", tnList);
		
		return SUCCESS;
	}
	
	
	/**
	 * 选择某个技术备忘录
	 * @return
	 * @throws Exception
	 */
	@Action("select_TechNote_stl")
	public String select_TechNote_stl() throws Exception{
		
		TechNote tn = projectService.findTechNoteById(Integer.parseInt(id));
		getSession().put("selectTechNote", tn);
		return null;
	}
	
	/**
	 * 删除技术备忘录
	 * @return
	 * @throws Exception
	 */
	@Action("del_techNote")
	public String del_techNote() throws Exception{
		projectService.delTechNote(Integer.parseInt(id));
		return null;
	};
	
	/**
	 * 更新全部的技术备忘录
	 * @return
	 * @throws Exception
	 */
	@Action("update_techNote")
	public String update_techNote() throws Exception{
		
		TechNote t = projectService.findTechNoteById(Integer.parseInt(id));
		t.setBriefDesc(briefDesc);
		t.setClosetime(closetime);
		t.setDetailDesc(detailDesc);
		t.setDoer(doer);
		t.setLevel(level);
		t.setReportDate(reportDate);
		t.setReporter(reporter);
		t.setState(state);
		t.setDetailDesc(detailDesc);
		t.setTechDemon(techDemon);
		
		if("新增问题".equals(state)){
			t.setOrders(1);
		}
		if("未安排计划".equals(state)){
			t.setOrders(2);
		}
		if("开发完成未上线".equals(state)){
			t.setOrders(3);
		}
		if("开发完成已经上线".equals(state)){
			t.setOrders(4);
		}
		if("已经完成".equals(state)){
			t.setOrders(5);
		}
		if("取消跟踪".equals(state)){
			t.setOrders(6);
		}
		
		projectService.saveTechNote(t);
		
		//把相关信息存到日志表里
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(t.getProject());
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr("'"+sessionUser.getRealName()+"'修改了'"+t.getProject().getProjectName()+"'项目下'"+t.getReporter()+"'提交的技术备忘录");
		
		projectService.saveProjectBlog(pb);
		
		return null;
	}
	
	/**
	 * 在项目下根据条件去查询技术备忘录,放在request里去展现
	 * @return
	 * @throws Exception
	 */
	@Action(value="query_project_techNote_by_Condition",results={@Result(name="success",location="/jsp/project/project_techNote.jsp")})
	public String query_project_techNote_by_Condition() throws Exception{
		
		String states = this.getState();  
		String[] arraycheck = states.split(", ");
		
		List<TechNote> projectTNList = new ArrayList<TechNote>();
		List<TechNote> projectTechNoteList = new ArrayList<TechNote>();
		
		for(String s : arraycheck){
			projectTNList = projectService.findProjectTechNoteByCondition(id,s,level,reporter,doer,begintime,endtime);
			projectTechNoteList.addAll(projectTNList);
		}
		
		
		getRequest().setAttribute("projectTNList", projectTechNoteList);
		
		getRequest().setAttribute("queryProjectTechNoteState", state);
		getRequest().setAttribute("queryProjectTechNoteLevel", level);
		
		getRequest().setAttribute("queryProjectTechNoteReporter", reporter);
		if(!(reporter == null || "所有".equals(reporter))){
			//根据username去找user
			User user = projectService.findUserByUsername(reporter);
			getRequest().setAttribute("queryProjectTechNoteReporterUser", user);
		}
		
		getRequest().setAttribute("queryProjectTechNoteDoer", doer);
		if(!(doer == null || "所有".equals(doer))){
			//根据username去找user
			User user = projectService.findUserByUsername(doer);
			getRequest().setAttribute("queryProjectTechNoteDoerUser", user);
		}
		
		getRequest().setAttribute("queryProjectTechNoteBegintime", begintime);
		getRequest().setAttribute("queryProjectTechNoteEndtime", endtime);
		
		return SUCCESS;
	}
	
	/**
	 * 切换至某项目下的技术备忘录，放session以展现
	 * @return
	 * @throws Exception
	 */
	@Action("look_project_techNote")
	public String look_project_techNote() throws Exception{
		
		int pid = Integer.parseInt(projectTechNoteId);
		Project p = projectService.findProjectById(pid);
		
		getSession().put("selectProject", p);
		
		List<TechNote> projectTechNoteList = projectService.finTechNoteByProjectId(pid);
		
		getSession().put("projectTechNoteList", projectTechNoteList);
		
		return null;
	}
	
	
	/**
	 * 修改某个技术备忘录的状态
	 * @return
	 * @throws Exception
	 */
	@Action("edit_TechNote_State")
	public String edit_TechNote_State() throws Exception{
		
		int tid = Integer.parseInt(editTechNoteStateid);
		TechNote t = projectService.findTechNoteById(tid);
		t.setState(editTechNoteState);
		t.setLevel(editTechNoteLevel);
		t.setTechDemon(editTechDemon);
		t.setClosetime(editTechCloseDate);
		
		if("新增问题".equals(editTechNoteState)){
			t.setOrders(1);
		}
		if("未安排计划".equals(editTechNoteState)){
			t.setOrders(2);
		}
		if("开发完成未上线".equals(editTechNoteState)){
			t.setOrders(3);
		}
		if("开发完成已经上线".equals(editTechNoteState)){
			t.setOrders(4);
		}
		if("已经完成".equals(editTechNoteState)){
			t.setOrders(5);
		}
		if("取消跟踪".equals(editTechNoteState)){
			t.setOrders(6);
		}
		
		projectService.updateTechNote(t);
		
		//把相关信息存到日志表里
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(t.getProject());
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr("'"+sessionUser.getRealName()+"'修改了'"+t.getProject().getProjectName()+"'项目下'"+t.getReporter()+"'提交的技术备忘录的状态");
		
		projectService.saveProjectBlog(pb);
		
		return null;
	}
	
	/**
	 * 添加技术备忘录
	 * @return
	 * @throws Exception
	 */
	@Action("add_techNote")
	public String add_techNote() throws Exception{
		int pid = Integer.parseInt(addtechNoteProjectId);
		Project project = projectService.findProjectById(pid);
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		closetime = df.format(date);
		
		//存技术备忘录
		TechNote t = new TechNote();
		t.setReporter(reporter);
		t.setBriefDesc(briefDesc);
		t.setDetailDesc(detailDesc);
		t.setDoer(doer);
		t.setType(type);
		t.setReportDate(reportDate);
		t.setLevel(level);
		
		t.setClosetime(closetime);
		t.setState("新增问题");
		t.setOrders(1);
		t.setTechDemon("无");
		
		t.setCreatetime(new GetNowTime().getNowTime());
		t.setProject(project);
		
		projectService.saveTechNote(t);
		
		
		//把相关信息存到日志表里
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(project);
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"添加了类型为："+t.getType()+"的技术备忘录！");
		
		projectService.saveProjectBlog(pb);
		
		return null;
	}
	
	/**
	 * 保存并发送邮件
	 * @return
	 */
	@Action("add_techNote_and_sendEmail")
	public String add_techNote_and_sendEmail(){
		int pid = Integer.parseInt(addtechNoteProjectId);
		Project project = projectService.findProjectById(pid);
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		closetime = df.format(date);
		
		//存技术备忘录
		TechNote t = new TechNote();
		t.setReporter(reporter);
		t.setBriefDesc(briefDesc);
		t.setDetailDesc(detailDesc);
		t.setDoer(doer);
		t.setLevel(level);
		t.setReportDate(reportDate);
		
		t.setClosetime(closetime);
		t.setTechDemon("无");
		t.setState("未完成");
		
		t.setCreatetime(new GetNowTime().getNowTime());
		t.setProject(project);
		
		projectService.saveTechNote(t);
		
		//发送邮件
		List<UserProject> upList = projectService.findUserProjectByPid(t.getProject().getId());
		
		User u = (User) getSession().get("session_user");
		
		String emailMsg = u.getRealName()+"新建了'"+t.getBriefDesc()+"'的技术备忘录！";
		String emailsubject = "'"+t.getProject().getProjectName()+"'项目下新建了技术备忘录！"; 
		
		for(UserProject up : upList){
			String sendEmailAddress = up.getUser().getEmail();
			MailUtil.sendMail(sendEmailAddress, emailsubject, emailMsg);
		}
		
		//把相关信息存到日志表里
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(project);
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"添加了类型为："+t.getType()+"的技术备忘录！");
		
		projectService.saveProjectBlog(pb);
		
		return null;
	}
	
	/**
	 * 添加项目下的技术备忘录
	 * @return
	 * @throws Exception
	 */
	@Action("add_project_techNote")
	public String add_project_techNote() throws Exception{
		
		int pid = Integer.parseInt(id); 
		Project project = projectService.findProjectById(pid);
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		closetime = df.format(date);
		
		//存技术备忘录
		TechNote t = new TechNote();
		t.setReporter(reporter);
		t.setBriefDesc(briefDesc);
		t.setDetailDesc(detailDesc);
		t.setDoer(doer);
		t.setType(type);
		t.setReportDate(reportDate);
		t.setLevel(level);
		
		t.setClosetime(closetime);
		t.setState("新增问题");
		t.setOrders(1);
		t.setTechDemon("无");
		
		t.setCreatetime(new GetNowTime().getNowTime());
		t.setProject(project);
		
		projectService.saveTechNote(t);
		
		//向项目日志里存数据
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(project);
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"添加了类型为："+t.getType()+"的技术备忘录！");
		
		projectService.saveProjectBlog(pb);
		return null;
	}
	
	
	
	/**
	 * 添加项目服务表上 选择服务表类型 后 根据类型去显示div
	 * @return
	 * @throws Exception
	 */
	@Action("selectServiceTypeToShowDiv")
	public String selectServiceTypeToShowDiv() throws Exception{
		
		
		getResponse().setContentType("application/json");
		List<ProjectTypeDefine> ptfList = projectService.findProjectTypeDefineBySerNo(serNo);
		
		List<String> infoTypeNoList = new ArrayList<String>();
		
		for(ProjectTypeDefine p : ptfList){
			infoTypeNoList.add(p.getInfoTypeNo());
		}
		//使用json把数据刷过去
		Gson gson = new Gson();
		String json = gson.toJson(infoTypeNoList);
		
		PrintWriter out = getResponse().getWriter();
		
		out.print(json);
		out.flush();
		out.close();
		
		return null;
	}
	

	@Override
	public String findAll() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 根据Id去查找项目，放到session中，以备编辑时用
	 */
	@Override
	@Action("editProject")
	public String findById() throws Exception {
		int ppid = Integer.parseInt(id);
		
		Project p = projectService.findProjectById(ppid);
		getSession().put("projectById", p);
		List<UserProject> upList = projectService.findUserProjectByPid(ppid);
		getSession().put("userInProject", upList);
		for(UserProject up : upList){
			if("manager".equals(up.getRole())){
				getSession().put("UserRole_manager", up);
			} else {
				getSession().put("UserRole_member", up);
			}
		}
		return null;
	}

	@Override
	public String update() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 修改某个项目信息(未完成，未添加日志)
	 */
	@Override
	@Action("editAndUpdateProject")
	public String edit() throws Exception {
		int ppid = Integer.parseInt(pid);
		//找到修改的项目，进行更新（没有更改成员）
		Project project = projectService.findProjectById(ppid);
		
		project.setProjectName(projectName);
		project.setDescr(desc);
		project.setProjectManager(manager);
		project.setProjectProcess(process);
		project.setClientName(clientName);
		project.setClientAddress(clientAddress);
		project.setProjectMember(members);
		
		projectService.saveProject(project);
		
		//向项目日志里存数据
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(project);
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"修改了："+project.getProjectName()+"的项目信息！");
		
		projectService.saveProjectBlog(pb);
		
		return null;
	}
	
	//------------------------项目下客户接口人的操作---------------------------
	
	/**
	 * 删除接口人
	 * @return
	 * @throws Exception
	 */
	@Action(value="delContactClient",results={@Result(name="success",location="/jsp/project/project_clients.jsp")})
	public String delContactClient() throws Exception{
		
		ClientContact cc = projectService.findClientContactByCid(Integer.parseInt(projectClientId));
		
		projectService.delClient(Integer.parseInt(projectClientId));
		
		//向项目日志里存数据
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(cc.getProject());
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"删除了名为："+cc.getContactName()+"客户联系人！");
		
		projectService.saveProjectBlog(pb);
		
		return SUCCESS;
	}
	
	/**
	 * 编辑客户接口人
	 * @return
	 * @throws Exception
	 */
	@Action("edit_project_client")
	public String edit_project_client() throws Exception{
		
		ClientContact cc = projectService.findClientContactByCid(Integer.parseInt(id));
		
		cc.setAddress(address);
		cc.setCompany(company);
		cc.setContactName(contactName);
		cc.setEmail(email);
		cc.setTel(tel);
		
		projectService.saveClientContact(cc);
		
		//向项目日志里存数据
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(cc.getProject());
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"修改了名为："+cc.getContactName()+"客户联系人的信息！");
		
		projectService.saveProjectBlog(pb);
		
		return null;
	}
	
	/**
	 * 选择一个客户接口人
	 * @return
	 * @throws Exception
	 */
	@Action("selectContactClient")
	public String selectContactClient() throws Exception{
		
		int cid = Integer.parseInt(projectClientId);
		ClientContact cc = projectService.findClientContactByCid(cid);
		getSession().put("ClientContact", cc);
		return null;
	}
	
	/**
	 * 查询所有客户接口人
	 * @return
	 * @throws Exception
	 */
	@Action(value="findAllClientContact",results={@Result(name="success",type="dispatcher",location="/jsp/project/project_clients.jsp")})
	public String findAllClientContact() throws Exception{
		
		List<ClientContact> ccList = projectService.findClientContactByProjectId(Integer.parseInt(pid));
		getRequest().setAttribute("ccList", ccList);
		return SUCCESS;
	};
	
	/**
	 * 查找项目下的客户接口人
	 * @return
	 * @throws Exception
	 */
	@Action("look_project_client")
	public String look_project_client() throws Exception{
		
		int pid = Integer.parseInt(projectClientId);
		List<ClientContact> clientContactList = projectService.findClientContactByProjectId(pid);
		getSession().put("clientContactList", clientContactList);
		return null;
	}
	/**
	 * 添加项目下的客户接口人
	 * @return
	 * @throws Exception
	 */
	@Action("add_project_client")
	public String add_project_client() throws Exception{
		int pid = Integer.parseInt(id);
		Project p = projectService.findProjectById(pid);
		
		ClientContact cc = new ClientContact();
		cc.setContactName(contactName);
		cc.setAddress(address);
		cc.setCompany(company);
		cc.setEmail(email);
		cc.setTel(tel);
		cc.setProject(p);
		
		projectService.saveClientContact(cc);
		
		//向项目日志里存数据
		User sessionUser = (User) getSession().get("session_user");
		ProjectBlog pb = new ProjectBlog();
		pb.setProject(p);
		pb.setCreater(sessionUser.getUsername());
		pb.setCreatetime(new GetNowTime().getNowTime());
		pb.setDescr(sessionUser.getRealName()+"添加了名为："+contactName+"项目联系人");
		projectService.saveProjectBlog(pb);
		return null;
	};
	
	//get set
	public String getProjectName() {
		return projectName;
	}
	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}
	public String getProjectManager() {
		return projectManager;
	}
	public void setProjectManager(String projectManager) {
		this.projectManager = projectManager;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public String getProjectProcess() {
		return projectProcess;
	}
	public void setProjectProcess(String projectProcess) {
		this.projectProcess = projectProcess;
	}
	public String getClientName() {
		return clientName;
	}
	public void setClientName(String clientName) {
		this.clientName = clientName;
	}
	public String getClientAddress() {
		return clientAddress;
	}
	public void setClientAddress(String clientAddress) {
		this.clientAddress = clientAddress;
	}
	public String getManager() {
		return manager;
	}
	public void setManager(String manager) {
		this.manager = manager;
	}
	public String getMembers() {
		return members;
	}
	public void setMembers(String members) {
		this.members = members;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getPid() {
		return pid;
	}
	public void setPid(String pid) {
		this.pid = pid;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getSupportDate() {
		return supportDate;
	}
	public void setSupportDate(String supportDate) {
		this.supportDate = supportDate;
	}
	public String getWorkContent() {
		return workContent;
	}
	public void setWorkContent(String workContent) {
		this.workContent = workContent;
	}
	public String getGoal() {
		return goal;
	}
	public void setGoal(String goal) {
		this.goal = goal;
	}
	public String getFocusContent() {
		return focusContent;
	}
	public void setFocusContent(String focusContent) {
		this.focusContent = focusContent;
	}
	public String getNextStep() {
		return nextStep;
	}
	public void setNextStep(String nextStep) {
		this.nextStep = nextStep;
	}
	public String getRivalMsg() {
		return rivalMsg;
	}
	public void setRivalMsg(String rivalMsg) {
		this.rivalMsg = rivalMsg;
	}
	public String getIdea() {
		return idea;
	}
	public void setIdea(String idea) {
		this.idea = idea;
	}
	public String getOther() {
		return other;
	}
	public void setOther(String other) {
		this.other = other;
	}
	public String getLeftProblem() {
		return leftProblem;
	}
	public void setLeftProblem(String leftProblem) {
		this.leftProblem = leftProblem;
	}
	public String getServer() {
		return server;
	}
	public void setServer(String server) {
		this.server = server;
	}
	public String getBegintime() {
		return begintime;
	}
	public void setBegintime(String begintime) {
		this.begintime = begintime;
	}
	public String getWorkNote() {
		return workNote;
	}
	public void setWorkNote(String workNote) {
		this.workNote = workNote;
	}
	public List<Sale> getSaleList() {
		return saleList;
	}
	public void setSaleList(List<Sale> saleList) {
		this.saleList = saleList;
	}
	public String getReporter() {
		return reporter;
	}
	public void setReporter(String reporter) {
		this.reporter = reporter;
	}
	public String getBriefDesc() {
		return briefDesc;
	}
	public void setBriefDesc(String briefDesc) {
		this.briefDesc = briefDesc;
	}
	public String getDetailDesc() {
		return detailDesc;
	}
	public void setDetailDesc(String detailDesc) {
		this.detailDesc = detailDesc;
	}
	public String getDoer() {
		return doer;
	}
	public void setDoer(String doer) {
		this.doer = doer;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getTechDemon() {
		return techDemon;
	}
	public void setTechDemon(String techDemon) {
		this.techDemon = techDemon;
	}
	public String getReportDate() {
		return reportDate;
	}
	public void setReportDate(String reportDate) {
		this.reportDate = reportDate;
	}
	public String getClosetime() {
		return closetime;
	}
	public void setClosetime(String closetime) {
		this.closetime = closetime;
	}
	public String getStarttime() {
		return starttime;
	}
	public void setStarttime(String starttime) {
		this.starttime = starttime;
	}
	public String getEndtime() {
		return endtime;
	}
	public void setEndtime(String endtime) {
		this.endtime = endtime;
	}
	public List<Project> getProjectList() {
		return projectList;
	}
	public void setProjectList(List<Project> projectList) {
		this.projectList = projectList;
	}
	public String getProcess() {
		return process;
	}
	public void setProcess(String process) {
		this.process = process;
	}
	public String getContactName() {
		return contactName;
	}
	public void setContactName(String contactName) {
		this.contactName = contactName;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getCompany() {
		return company;
	}
	public void setCompany(String company) {
		this.company = company;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getLevel() {
		return level;
	}
	public void setLevel(String level) {
		this.level = level;
	}
	public String getAddtechNoteProjectId() {
		return addtechNoteProjectId;
	}
	public void setAddtechNoteProjectId(String addtechNoteProjectId) {
		this.addtechNoteProjectId = addtechNoteProjectId;
	}
	public String getEditTechNoteStateid() {
		return editTechNoteStateid;
	}
	public void setEditTechNoteStateid(String editTechNoteStateid) {
		this.editTechNoteStateid = editTechNoteStateid;
	}
	public String getEditTechNoteState() {
		return editTechNoteState;
	}
	public void setEditTechNoteState(String editTechNoteState) {
		this.editTechNoteState = editTechNoteState;
	}
	public List<File> getDocList() {
		return docList;
	}
	public void setDocList(List<File> docList) {
		this.docList = docList;
	}
	public List<String> getDocListFileName() {
		
		//return docListFileName;
		
		List<String> downNameList = docListFileName;
		String str = new String();
		for(int i = 0; i < downNameList.size();i++){
			try {
				str = new String(downNameList.get(i).getBytes(),"ISO8859-1");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			downNameList.set(i, str);
		}
		return downNameList;
		
	}
	public void setDocListFileName(List<String> docListFileName) {
		this.docListFileName = docListFileName;
	}
	public List<String> getDocListContentType() {
		return docListContentType;
	}
	public void setDocListContentType(List<String> docListContentType) {
		this.docListContentType = docListContentType;
	}
	public List<String> getFileNameByHand() {
		return fileNameByHand;
	}
	public void setFileNameByHand(List<String> fileNameByHand) {
		this.fileNameByHand = fileNameByHand;
	}

	/*public File getDoc() {
		return doc;
	}
	public void setDoc(File doc) {
		this.doc = doc;
	}
	public String getDocFileName() {
		return docFileName;
	}
	public void setDocFileName(String docFileName) {
		this.docFileName = docFileName;
	}
	public String getDocContentType() {
		return docContentType;
	}
	public void setDocContentType(String docContentType) {
		this.docContentType = docContentType;
	}
	public String getFileNameByHand() {
		return fileNameByHand;
	}
	public void setFileNameByHand(String fileNameByHand) {
		this.fileNameByHand = fileNameByHand;
	}*/
	public String getSelectProjectId() {
		return selectProjectId;
	}
	public void setSelectProjectId(String selectProjectId) {
		this.selectProjectId = selectProjectId;
	}
	
	public String getMime() {
		return mime;
	}
	public void setMime(String mime) {
		this.mime = mime;
	}
	public String getFileName() throws Exception {
		//return new String(fileName.getBytes("UTF-8"),"ISO8859-1");
		return fileName;
	}
	public void setFileName(String fileName) throws UnsupportedEncodingException {
		//this.fileName = fileName;
		this.fileName = new String(fileName.getBytes("GBK"), "ISO8859-1");
	}
	public long getFileLength() {
		return fileLength;
	}
	public void setFileLength(long fileLength) {
		this.fileLength = fileLength;
	}
	public String getDocid() {
		return docid;
	}
	public void setDocid(String docid) {
		this.docid = docid;
	}
	public String getProjectTechNoteId() {
		return projectTechNoteId;
	}
	public void setProjectTechNoteId(String projectTechNoteId) {
		this.projectTechNoteId = projectTechNoteId;
	}
	public String getProjectClientId() {
		return projectClientId;
	}
	public void setProjectClientId(String projectClientId) {
		this.projectClientId = projectClientId;
	}
	public String getSerNo() {
		return serNo;
	}
	public void setSerNo(String serNo) {
		this.serNo = serNo;
	}
	public String getServiceNo() {
		return serviceNo;
	}
	public void setServiceNo(String serviceNo) {
		this.serviceNo = serviceNo;
	}
	public String getI1() {
		return i1;
	}
	public void setI1(String i1) {
		this.i1 = i1;
	}
	public String getI2() {
		return i2;
	}
	public void setI2(String i2) {
		this.i2 = i2;
	}
	public String getI3() {
		return i3;
	}
	public void setI3(String i3) {
		this.i3 = i3;
	}
	public String getI4() {
		return i4;
	}
	public void setI4(String i4) {
		this.i4 = i4;
	}
	public String getI5() {
		return i5;
	}
	public void setI5(String i5) {
		this.i5 = i5;
	}
	public String getI6() {
		return i6;
	}
	public void setI6(String i6) {
		this.i6 = i6;
	}
	public String getI7() {
		return i7;
	}
	public void setI7(String i7) {
		this.i7 = i7;
	}
	public String getI8() {
		return i8;
	}
	public void setI8(String i8) {
		this.i8 = i8;
	}
	public String getI9() {
		return i9;
	}
	public void setI9(String i9) {
		this.i9 = i9;
	}
	public String getI10() {
		return i10;
	}
	public void setI10(String i10) {
		this.i10 = i10;
	}
	public String getI11() {
		return i11;
	}
	public void setI11(String i11) {
		this.i11 = i11;
	}
	public String getI12() {
		return i12;
	}
	public void setI12(String i12) {
		this.i12 = i12;
	}
	public String getI13() {
		return i13;
	}
	public void setI13(String i13) {
		this.i13 = i13;
	}
	public String getI14() {
		return i14;
	}
	public void setI14(String i14) {
		this.i14 = i14;
	}
	public String getI15() {
		return i15;
	}
	public void setI15(String i15) {
		this.i15 = i15;
	}
	public String getHours() {
		return hours;
	}
	public void setHours(String hours) {
		this.hours = hours;
	}
	public String getOtherPeople() {
		return otherPeople;
	}
	public void setOtherPeople(String otherPeople) {
		this.otherPeople = otherPeople;
	}
	public String getServiceType() {
		return serviceType;
	}
	public void setServiceType(String serviceType) {
		this.serviceType = serviceType;
	}
	public String getOurPeoples() {
		return ourPeoples;
	}
	public void setOurPeoples(String ourPeoples) {
		this.ourPeoples = ourPeoples;
	}
	public String getProjectServicesId() {
		return projectServicesId;
	}
	public void setProjectServicesId(String projectServicesId) {
		this.projectServicesId = projectServicesId;
	}
	public String getEditTechNoteLevel() {
		return editTechNoteLevel;
	}
	public void setEditTechNoteLevel(String editTechNoteLevel) {
		this.editTechNoteLevel = editTechNoteLevel;
	}
	public String getEditTechDemon() {
		return editTechDemon;
	}
	public void setEditTechDemon(String editTechDemon) {
		this.editTechDemon = editTechDemon;
	}
	public String getProjectServiceType() {
		return projectServiceType;
	}
	public void setProjectServiceType(String projectServiceType) {
		this.projectServiceType = projectServiceType;
	}
	public String getInfoType() {
		return infoType;
	}
	public void setInfoType(String infoType) {
		this.infoType = infoType;
	}
	public String getPsid() {
		return psid;
	}
	public void setPsid(String psid) {
		this.psid = psid;
	}
	public String getEditTechCloseDate() {
		return editTechCloseDate;
	}
	public void setEditTechCloseDate(String editTechCloseDate) {
		this.editTechCloseDate = editTechCloseDate;
	}
	public String getBlurByProjectName() {
		return blurByProjectName;
	}
	public void setBlurByProjectName(String blurByProjectName) {
		this.blurByProjectName = blurByProjectName;
	}
	public String getBlurByClientName() {
		return blurByClientName;
	}
	public void setBlurByClientName(String blurByClientName) {
		this.blurByClientName = blurByClientName;
	}
	public String getInsertClientContact() {
		return insertClientContact;
	}
	public void setInsertClientContact(String insertClientContact) {
		this.insertClientContact = insertClientContact;
	}
	public String getInsertLabor() {
		return insertLabor;
	}
	public void setInsertLabor(String insertLabor) {
		this.insertLabor = insertLabor;
	}
	public String getQlevel() {
		return qlevel;
	}
	public void setQlevel(String qlevel) {
		this.qlevel = qlevel;
	}
	//......
	@Autowired
	public void setProjectService(ProjectService projectService) {
		this.projectService = projectService;
	}
	@Autowired
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	@Autowired
	public void setLaborService(LaborService laborService) {
		this.laborService = laborService;
	}

	
	
	

	
}
